import { USER } from '@/store/mutationsTypes';
import { authService } from '@/service';

export default {
  state: {
    // token里的用户信息
    tokenUserInf: {},
  },
  mutations: {
    /* eslint注释请不要删除 */
    /* eslint-disable no-unused-expressions */
    [USER.UPDATE_TOKEN_USER](state, data) {
      /* 修改token用户信息 */
      state.tokenUserInf = data;
    },
  },
  actions: {
    async [USER.UPDATE_TOKEN_USER_ASYNC]({ commit }) {
      /* 修改token用户信息 */
      const data = await authService.getUserInfoByToken();
      if (data) {
        return commit(USER.UPDATE_TOKEN_USER, data);
      }
    },
  },
  getters: {
    [USER.GET_TOKEN_USER](state) {
      /* token用户信息 */
      return state.tokenUserInf;
    },
  },
};
